const { Sequelize, DataTypes } = require("sequelize");
const sequelize = require('.')
const Employee = sequelize.define(
  "Employee",
  {
    id: {
      type: Sequelize.INTEGER,
      primaryKey: true,
      autoIncrement: true,
    },
    code: {
      type: Sequelize.INTEGER,
      unique: true,
    },
    name: {
      type: DataTypes.STRING,
      allowNull: false,
      defaultValue: null,
    },
    enName: {
      type: DataTypes.STRING,
      defaultValue: null,
    },
    email: {
      type: DataTypes.STRING,
      defaultValue: null,
    },
    phone: {
      type: DataTypes.STRING,
      defaultValue: null,
    },
    level: {
      type: DataTypes.STRING,
      defaultValue: null,
    },
    group: {
      type: DataTypes.STRING,
      defaultValue: null,
    }
  },
  {
    timestamps: false,
  }
);

async function deleteAll() {
  await Employee.destroy({
    where: {},
    truncate: true,
  });
}
async function create(params) {
  await Employee.create({
    code: 376116,
    name: '李顺财',
    enName: 'ShunCai_Li',
    level: '研发',
    group: '应用开发2组',
    email: '',
    phone: '15155669900'
  });
}
(async () => {
  await Employee.sync(); // Creates the table if it doesn't exist
  // await deleteAll();
  // await create()
})();

module.exports = Employee